﻿@model lwzlz.Application.System.Dto.CodeTypeOutput
@{
    ViewBag.Title = "View";
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
<form class="layui-form layui-form-pane">
    @Html.AntiForgeryToken()
    <input type="hidden" value="@Model.Id" name="Id" />
    <div class="layui-form-item">
        <div class="layui-col-md6 layui-col-sm12">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="tel" autocomplete="off" placeholder="请输入类型名称" class="layui-input"
                       lay-verify="required" name="CodeName" value="@Model.CodeName" />
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-col-md6 layui-col-sm12">
            <label class="layui-form-label">编码</label>
            <div class="layui-input-block">
                <input type="tel" autocomplete="off" placeholder="请输入类型编码" class="layui-input"
                       lay-verify="required" name="Code" value="@Model.Code" />
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-col-md6 layui-col-sm12">
            <label class="layui-form-label">上级</label>
            <div class="layui-input-block">
                @Html.DropDownList("ParentId", ViewBag.TypeList as IEnumerable<SelectListItem>, new Dictionary<string, object> { { "lay-search", "" }, { "lay-verify", "required" }, { "lay-filter", "filter_ParentId" } })
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="Save">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" id="btnCancel">取消</button>
        </div>
    </div>
</form>
@section scripts{
    <script type="text/javascript">
        var $, layer;
        layui.use(['form'], function () {
            var form = layui.form;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;


            var postUrl = '@(Url.Action(Model.Id > 0 ? "TypeEdit" : "TypeAdd", "Code"))';

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });

            // 监听提交
            form.on('submit(Save)', function (data) {
                var loading = layer.load();
                $.post(postUrl, data.field,
                    function (result) {
                        layer.close(loading);
                        if (result.Success) {
                            layer.msg(result.Message, { icon: 1, time: 2000 });
                            parent.LoadTree();
                            layer_close();
                        } else {
                            layer.alert(result.Message, { icon: 2 });
                        }
                    });
                return false;
            })


        });
    </script>
}
